package cn.lbd.arithmetic.sort;

import org.junit.Test;

import java.util.Arrays;

public class InsertSort {

    private static void sort(int[] array) {
        for (int i = 1; i < array.length; i++) {
            int value = array[i];
            int index = i - 1;
            while (index >= 0 && value < array[index]) {
                array[index + 1] = array[index];
                index--;
            }
            array[index + 1] = value;
            System.out.println("第" + (i) + "轮排序：" + Arrays.toString(array));
        }
    }


    public static void main(String[] args) {
        int[] array = {0, 2, 1, 4, 3, 5, 7, 6, 9, 8};
        sort(array);
    }


    //80000数据0.575
    @Test
    public void batchTest() {
        int[] arr = new int[80000];
        for (int i = 0; i < 80000; i++) {
            arr[i] = (int) (Math.random() * 8000000);
        }

        long start = System.currentTimeMillis();

        sort(arr);

        long end = System.currentTimeMillis();

        System.out.println((double) (end - start) / 1000);
    }
}
